"""
学生信息管理后台
"""
from django.contrib import admin
from .models import School, Major, Grade, Student, TeacherStudentAssignment


@admin.register(School)
class SchoolAdmin(admin.ModelAdmin):
    """校区管理"""

    list_display = ['name', 'code', 'principal', 'phone', 'is_active', 'created_at']
    list_filter = ['is_active', 'created_at']
    search_fields = ['name', 'code', 'principal']
    ordering = ['name']


@admin.register(Major)
class MajorAdmin(admin.ModelAdmin):
    """专业管理"""
    
    list_display = ['name', 'description', 'is_active']
    list_filter = ['is_active', 'created_at']
    search_fields = ['name', 'description']
    ordering = ['name']


@admin.register(Grade)
class GradeAdmin(admin.ModelAdmin):
    """年级管理"""
    
    list_display = ['name', 'description', 'is_active']
    list_filter = ['is_active']
    search_fields = ['name', 'description']
    ordering = ['name']



@admin.register(Student)
class StudentAdmin(admin.ModelAdmin):
    """学生管理"""
    
    list_display = [
        'student_id', 'name', 'gender', 'grade', 'status',
        'employment_status', 'resume_status'
    ]
    list_filter = [
        'grade', 'gender', 'status',
        'employment_status', 'resume_status'
    ]
    search_fields = ['student_id', 'name', 'phone', 'email']
    ordering = ['student_id']
    
    fieldsets = (
        ('基本信息', {
            'fields': ('user', 'student_id', 'class_info', 'name', 'gender', 'birth_date')
        }),
        ('联系信息', {
            'fields': ('id_card', 'phone', 'email', 'address')
        }),
        ('学业信息', {
            'fields': ('enrollment_date', 'expected_graduation_date', 'status', 'gpa')
        }),
        ('就业信息', {
            'fields': ('employment_status', 'employment_date', 'company_name', 'position', 'salary')
        }),
        ('状态信息', {
            'fields': ('resume_status', 'interview_count', 'last_interview_date', 'advisor')
        }),
        ('其他信息', {
            'fields': ('notes',)
        }),
    )


@admin.register(TeacherStudentAssignment)
class TeacherStudentAssignmentAdmin(admin.ModelAdmin):
    """师生分配关系管理"""
    
    list_display = ['teacher', 'student', 'assignment_type', 'assigned_date', 'is_active']
    list_filter = ['assignment_type', 'is_active', 'assigned_date']
    search_fields = ['teacher__username', 'student__name', 'student__student_id']
    ordering = ['-assigned_date']
